package adapletplugin.commands;

import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.jface.window.Window;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.PlatformUI;

import adapletplugin.MatrixOperations;
import adapletplugin.dialogs.LoginDialog;

public class Login extends AbstractHandler
{

	@Override
	public Object execute(ExecutionEvent event) throws ExecutionException
	{
		MatrixOperations mxops = new MatrixOperations();

		Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();

		LoginDialog loginDialog = new LoginDialog(shell);
		loginDialog.create();

		loginDialog.open();

		if (loginDialog.getReturnCode() == Window.OK)
		{
			mxops.setHost(loginDialog.getHost());
			mxops.setPassword(loginDialog.getPass());
			mxops.setUser(loginDialog.getUser());

			try
			{
				// boolean loginAttempt = mxops.login();
				boolean loginAttempt = false;

				System.out.println("Login Attempt Success: " + loginAttempt);
			} catch (Exception e)
			{
				// TODO handle exception
				System.out.println("Exception while trying to login");
				e.printStackTrace();
			}
		}

		return null;
	}

}
